//--------------------------------------------------------------------
#ifndef _dkfile_ps2kbd_h
#define _dkfile_ps2kbd_h
//--------------------------------------------------------------------

#include "dkfile.h"

//--------------------------------------------------------------------

#define DKPS2KBD_FLAG_TERMINAL	(1<<0)	// this device is active for terminal io


struct _dk_ps2kbd
{
	uint8_t _flag;

	uint16_t rx_buflen;					// total size of rx buffer (in bytes)
	uint16_t rx_buflimit;				// limit in number of bytes at which to assert flow control
	uint8_t *rx_buffer;					// circular buffer for received data (note: if this is changed from 128 byte len, code requires changes elsewhere also)
	volatile uint16_t rx_wr_ptr, rx_rd_ptr;		// will be pointed at dkps2kbd0_rx_buffer, dkps2kbd0_rx_wr_ptr, dkps2kbd0_rx_rd_ptr, etc
};



extern int dkps2kbd_open( DKFILE *stream );
extern int dkps2kbd_close( void *deviceinfo );
extern int dkps2kbd_read_byte(void *deviceinfo);
extern int dkps2kbd_write_byte(void *deviceinfo, int c);
extern int dkps2kbd_read_bytes(void *deviceinfo, int n, void *ptr);
extern int dkps2kbd_write_bytes(void *deviceinfo, int n, void *ptr );
extern int dkps2kbd_seek(void *deviceinfo, off_t offset, int whence);
extern fpos_t dkps2kbd_pos(void *deviceinfo);
extern int dkps2kbd_eof(void *deviceinfo);
extern int dkps2kbd_error(void *deviceinfo);


extern struct _dkdeviceio ps2kbddeviceio;
extern struct _dk_ps2kbd dkps2kbd[1];


// DKKEYCLKTIMEOUT sets timeout when waiting for clk from ps2 keyboard, in increments of 10us (dkkeyboard_sendcmd)
#define DKKEYCLKTIMEOUT		250

//--------------------------------------------------------------------
//int dkkeyboard_init(void);
//int dkkeyboard_sendcmd( uint8_t c );
//void decode(unsigned char sc);
//void put_kbbuff( char data );

extern unsigned char unshifted[][2];
extern unsigned char  shifted[][2];

//--------------------------------------------------------------------
#endif	// !_dkfile_ps2kbd_h
//--------------------------------------------------------------------
